﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// player跟随摄像机
/// </summary>
public class Camera3D : MonoBehaviour
{
    /// <summary>
    /// 间隔距离
    /// </summary>
    private float m_DistanceAway = 11.0f;
    /// <summary>
    /// 间隔高度
    /// </summary>
    private float m_DistanceHeight = 12.0f;
    /// <summary>
    /// 平滑值
    /// </summary>
    private float smooth = 2f;
    /// <summary>
    /// 目标点
    /// </summary>
    private Vector3 m_TargetPostion;
    /// <summary>
    /// 参照点
    /// </summary>
    private Transform m_follow;


    private void Start()
    {
        ///获取玩家的位置
        m_follow = GameObject.Find("Player").transform;
        transform.rotation = Quaternion.Euler(new Vector3(28,90,0));
    }
    
    /// <summary>
    /// 操作摄像机
    /// </summary>
    private void LateUpdate()
    {
        m_TargetPostion = m_follow.position + Vector3.up*m_DistanceHeight- m_follow.forward * m_DistanceAway;
        transform.position = m_TargetPostion;
        // transform.position = Vector3.Lerp(transform.position, m_TargetPostion, Time.deltaTime * smooth);
    }
}
